package com.grape.dto;

import com.grape.utils.BigDecimalUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
public class StatisticalCurrentMonthDTO {

    /** 收入 */
    @ApiModelProperty(value = "收入")
    private BigDecimal income;

    /** 支出 */
    @ApiModelProperty(value = "支出")
    private BigDecimal expenses;

    /** 余额 */
    @ApiModelProperty(value = "余额")
    private BigDecimal balance;

    public void initBalance() {
        if (income == null) {
            income = BigDecimal.ZERO;
        }
        if (expenses == null) {
            expenses = BigDecimal.ZERO;
        }
        income = income.setScale(2, RoundingMode.HALF_UP);
        expenses = expenses.setScale(2, RoundingMode.HALF_UP);
        balance = BigDecimalUtil.sub(income, expenses).setScale(2, RoundingMode.HALF_UP);
    }
}
